package org.cocos2dx.javascript;

import android.annotation.TargetApi;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.KeyEvent;
import android.view.ViewConfiguration;
import android.view.WindowManager;
import android.widget.Toast;

import com.pelbs.book99998.wxapi.WXEntryActivity;

import org.cocos2dx.javascript.Advert.core.AdSdkBridge;
import org.cocos2dx.javascript.Battery.BatteryReceiver;
import org.cocos2dx.javascript.Camera.CameraMgr;
import org.cocos2dx.javascript.DownLoad.DownloadMgr;
import org.cocos2dx.javascript.Mob.MobCallBack;
import org.cocos2dx.javascript.Mob.PhoneLoginMgr;
import org.cocos2dx.javascript.Voice.AudioManager;
import org.cocos2dx.javascript.Voice.AudioMediaManager;
import org.cocos2dx.javascript.Voice.MediaManager;
import org.cocos2dx.lib.Cocos2dxActivity;
import org.cocos2dx.lib.Cocos2dxHelper;
import org.cocos2dx.lib.Cocos2dxJavascriptJavaBridge;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

//import com.google.android.gms.appindexing.Action;
////import com.google.android.gms.appindexing.AppIndex;
//import com.google.android.gms.appindexing.Thing;
////import com.google.android.gms.common.api.GoogleApiClient;

/**
 * Created by guoliangxuan on 2017/3/24.
 */

public class NativeMgr /* extends AppActivity */ {
    public static AppActivity app = null;
    public static Handler mJniHandler;

    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    // private GoogleApiClient client;

    public static void init(AppActivity app) {
        org.cocos2dx.javascript.NativeMgr.app = app;
    }

    // 登录入口
    public static void OnWeChatLogin() {
        // SendWXSDKManager.OnJSToAndroidLogin();
        Intent intent = new Intent(Cocos2dxActivity.getContext(), WXEntryActivity.class);
        intent.putExtra(Contants.WX_Login, Contants.WX_Login);
        Cocos2dxActivity.getContext().startActivity(intent);
    }

    // 微信分享入口
    public static void OnWeChatShare(String title, String description, String urlStr, String flag) {
        // SendWXSDKManager.OnJSToAndroidShare(title, description, urlStr, flag);
        Intent intent = new Intent(Cocos2dxActivity.getContext(), WXEntryActivity.class);
        intent.putExtra(Contants.WX_ShareHttp, Contants.WX_ShareHttp);
        intent.putExtra(Contants.WX_ShareTitle, title);
        intent.putExtra(Contants.WX_ShareDescription, description);
        intent.putExtra(Contants.WX_ShareURL, urlStr);
        intent.putExtra(Contants.WX_ShareFlag, Integer.parseInt(flag));
        Cocos2dxActivity.getContext().startActivity(intent);
    }

    public static void OnWeChatShareImage(String imagePath, String flag) {
        // SendWXSDKManager.OnJSToAndroidShareImage(imagePath, flag);
        Intent intent = new Intent(Cocos2dxActivity.getContext(), WXEntryActivity.class);
        intent.putExtra(Contants.WX_ShareImage, Contants.WX_ShareImage);
        intent.putExtra(Contants.WX_ShareImagePath, imagePath);
        intent.putExtra(Contants.WX_ShareFlag, Integer.parseInt(flag));
        Cocos2dxActivity.getContext().startActivity(intent);

    }

    public static void OnWeChatShareText(String test, String flag) {
        Intent intent = new Intent(Cocos2dxActivity.getContext(), WXEntryActivity.class);
        intent.putExtra(Contants.WX_ShareText, Contants.WX_ShareText);
        intent.putExtra(Contants.WX_ShareFlag, Integer.parseInt(flag));
        intent.putExtra(Contants.WX_ShareDescription, test);
        Cocos2dxActivity.getContext().startActivity(intent);
    }

    // 支付入口
    public static void OnWeChatPay(String jsonData) {
        // WXPayManager.OnJSToAndroidWeChatPay(jsonData);
        Intent intent = new Intent(Cocos2dxActivity.getContext(), WXEntryActivity.class);
        intent.putExtra(Contants.WX_pay, Contants.WX_pay);
        intent.putExtra(Contants.WX_payData, jsonData);
        Cocos2dxActivity.getContext().startActivity(intent);
    }

    // 跳转设置页面
    public static void jumpToPhoneSetting() {
        AppActivity.getInstance().jumpToAppPrivacySetting(Cocos2dxActivity.getContext());
    }

    // 打开微信
    public static void openWeiXin() {
        Intent intent = new Intent(Cocos2dxActivity.getContext(), WXEntryActivity.class);
        intent.putExtra(Contants.WX_pay, Contants.WX_Open);
        Cocos2dxActivity.getContext().startActivity(intent);

        /*
         * Intent intent =
         * getPackageManager().getLaunchIntentForPackage("com.tencent.mm");
         * if (intent != null) {
         * intent.putExtra("type", "110");
         * intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         * app.startActivity();
         * }
         * 
         * 
         * PackageManager manager = getPackageManager();
         * Intent launchIntentForPackage =
         * manager.getLaunchIntentForPackage("com.tencent.mm");
         * startActivity(launchIntentForPackage);
         */
    }

    // 手机号登录
    public static void phoneLogin() throws JSONException {
        MobCallBack mCallBack = new MobCallBack() {
            @Override
            public void onSuccess(String strJson) throws JSONException {

            };

            // 链接或者地址有误
            @Override
            public void onFail(String strError) throws JSONException {

            };
        };
        PhoneLoginMgr.getInstance().login(mCallBack);
    }

    // 获取网页参数入口
    public static String GetQuery() {
        String query = app.GetQueryStr();
        return query;
    }

    /**
     * 2 * 获取版本号
     * 3 * @return 当前应用的版本号
     * 4
     */
    public static String getPackageVersion() {
        try {
            PackageManager manager = Cocos2dxActivity.getContext().getPackageManager();
            PackageInfo info = manager.getPackageInfo(Cocos2dxActivity.getContext().getPackageName(), 0);
            String version = info.versionName;
            Log.e("getVersion", "version=" + version);
            return version;
        } catch (Exception e) {
            e.printStackTrace();
            return "0.0.0";
        }
    }

    /**
     * 是否要打开隐私页面
     */
    public static boolean OpenPrivacyState() {
        boolean openState = AppActivity.getInstance().IsOpenPrivacyDialog();
        return openState;
    }

    public static boolean isExitOnce = false;
    /*
     * 返回上级界面的回调
     */
    public static void OnKeyCodeBack(boolean result) {
        if (!result) {
            // 未处理，调用 super.onKeyDown，模拟手动触发
            if (isExitOnce){
                AppActivity.getInstance().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        AppActivity.getInstance().callSuperOnKeyDown(KeyEvent.KEYCODE_BACK);
                    }
                });
                isExitOnce = false;
            }
            else{
                isExitOnce = true;
                AppActivity.getInstance().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(AppActivity.getInstance(),"再按一次退出", Toast.LENGTH_SHORT).show();
                    }
                });

            }

        }
        else{
            isExitOnce = false;
        }
    }

    /**
     * 开始主动去获取权限
     */
    public static void RequestPrivacyPermission() {
        AppActivity.getInstance().RequestPrivacyPermission();
    }

    /**
     * 2 * 获取包信息
     * 3 * @return 当前应用的包名
     * 4
     */
    public static PackageInfo getPackageInfo() {
        try {
            PackageManager manager = Cocos2dxActivity.getContext().getPackageManager();
            PackageInfo info = manager.getPackageInfo(Cocos2dxActivity.getContext().getPackageName(), 0);
            return info;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 2 * 获取应用的厂商
     * 3 * @return 当前应用的厂商
     * 4
     */
    public static String getBrandInfo() {
        Log.e("getBrandInfoandroid.os.Build.BRAND", android.os.Build.BRAND);
        return android.os.Build.BRAND;
    }

    /**
     * 通过包名 在应用商店打开应用
     *
     * @param marketPkg 商店
     */

    public static void goToMarket(String marketPkg, String appPkg) {
        try {
            // String appPkg = Cocos2dxActivity.getContext().getPackageName();
            Log.e("goToMarket", "appPkg=" + appPkg);
            if (TextUtils.isEmpty(appPkg))
                return;

            Uri uri = Uri.parse("market://details?id=" + appPkg);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            if (!TextUtils.isEmpty(marketPkg)) {
                intent.setPackage(marketPkg);
            }
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            Cocos2dxActivity.getContext().startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void setAppCompany(String appCompany) {
        try {
            Log.e("setAppCompany", "appCompany=" + appCompany);
            if (TextUtils.isEmpty(appCompany))
                return;
            String packageName = Cocos2dxActivity.getContext().getPackageName();
            PhoneLoginMgr.getInstance().setAppInfo(appCompany, packageName.substring(14));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /*
     * 从网络下载文件 filename 为deleteString时去除
     */
    public static void downLoadFile(final String urls, final String fileName, final String savePath,
            final String downloadType) throws IOException {
        Log.e("downLoadFile", "url=" + urls + ",filename=" + fileName + ",savePath=" + savePath);
        if (fileName.equals("deleteString")) {
            DownloadMgr.downLoadFile(urls, "", savePath, downloadType);
        } else {
            DownloadMgr.downLoadFile(urls, fileName, savePath, downloadType);
        }
    }

    /*
     * 异步回调js
     */
    public static void OnCallBackToJs(String callType, String data) {
        Log.e("OnCallBackToJs", "callType=" + callType + ",data=" + data);
        final String callData = String.format("app.Client.OnNativeNotify('%s','%s')", callType, data);
        // 一定要在GL线程中执行
        Cocos2dxHelper.runOnGLThread(new Runnable() {
            @Override
            public void run() {
                Cocos2dxJavascriptJavaBridge.evalString(callData);
            }
        });
    }

    /**
     * 从网络Url中下载文件
     *
     * @param urls
     * @param fileName
     * @param savePath
     * @throws IOException
     */
    public static void downLoadFromUrl(final String urls, final String fileName, final String savePath)
            throws IOException {
        Log.e("downLoadFromUrl", "url=" + urls + ",filename=" + fileName + ",savePath=" + savePath);
        DownloadMgr.downLoadFromUrl(urls, fileName, savePath);
    }

    // @Override
    // protected void onCreate(Bundle savedInstanceState) {
    // super.onCreate(savedInstanceState);
    //
    // // ATTENTION: This was auto-generated to implement the App Indexing API.
    // // See https://g.co/AppIndexing/AndroidStudio for more information.
    // client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
    // }

    // /**
    // * ATTENTION: This was auto-generated to implement the App Indexing API.
    // * See https://g.co/AppIndexing/AndroidStudio for more information.
    // */
    // public Action getIndexApiAction() {
    // Thing object = new Thing.Builder()
    // .setName("NativeMgr Page") // TODO: Define a title for the content shown.
    // // TODO: Make sure this auto-generated URL is correct.
    // .setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]"))
    // .build();
    // return new Action.Builder(Action.TYPE_VIEW)
    // .setObject(object)
    // .setActionStatus(Action.STATUS_TYPE_COMPLETED)
    // .build();
    // }

    // @Override
    // public void onStart() {
    // super.onStart();
    // // ATTENTION: This was auto-generated to implement the App Indexing API.
    // // See https://g.co/AppIndexing/AndroidStudio for more information.
    // client.connect();
    // AppIndex.AppIndexApi.start(client, getIndexApiAction());
    // }

    // @Override
    // public void onStop() {
    // super.onStop();
    // // ATTENTION: This was auto-generated to implement the App Indexing API.
    // // See https://g.co/AppIndexing/AndroidStudio for more information.
    // AppIndex.AppIndexApi.end(client, getIndexApiAction());
    // client.disconnect();
    // }

    // 检查是否有录音权限
    public static boolean checkAudioPermissions() {
        return AudioManager.getInstance().checkPermissions();
    }

    // 播放音频
    public static void playAuido(String fileName) {
        AudioMediaManager.getInstance().play(fileName);
    }

    // 以特定的速度播放音频
    public static void playAuidoSpeed(String fileName) {
        AudioMediaManager.getInstance().play(fileName);
    }

    // 停止音频
    public static void stopAuido() {
        Log.e("stopAuido", "AudioMediaManager");
        AudioMediaManager.getInstance().release();
    }

    // 继续播放
    public static void resumeAuido() {
        AudioMediaManager.getInstance().resume();
    }

    // 暂停播放
    public static void pauseAuido() {
        AudioMediaManager.getInstance().pause();
    }

    // 设置播放速度

    public static void setPlaySpeed(String speed) {
        AudioMediaManager.getInstance().setPlaySpeed(speed);
    }

    //////////////////////////////////// 录音////////////////////////////////////
    // 开始录音
    public static void startRecord(String fileName) {
        AudioManager.getInstance().prepareAudio(fileName);
    }

    // 停止录音
    public static void stopRecord() {
        AudioManager.getInstance().release();
    }

    // 播放录音
    public static void playerRecord(String fileName) {
        MediaManager.getInstance().playSound(fileName);
    }

    // 停止播放录音
    public static void stopPlayerRecord() {
        MediaManager.getInstance().stop();
    }

    // 继续播放
    public static void resumePlayerRecord() {
        MediaManager.getInstance().resume();
    }

    // 暂停播放
    public static void pausePlayerRecord() {
        MediaManager.getInstance().pause();
    }

    // 获取当前经纬度
    public static void GetLocation() {
        Log.e("GetLocation", "startLocation");
        // Location.getInstance().startLocation();
        // Location.getInstance().clearGetLocationThredCount();
    }

    // 根据经纬度获取距离
    public static void GetDistance(String data) {
        Log.e("GetDistance", "data=" + data);
        double startlatitude = 0.0D, startlongitude = 0.0D, endlatitude = 0.0D, endlongitude = 0.0D;
        try {
            JSONObject jb = new JSONObject(data);
            Log.e("GetDistance", "jb=" + jb.toString());
            startlatitude = jb.getDouble("startlatitude");
            startlongitude = jb.getDouble("startlongitude");
            endlatitude = jb.getDouble("endlatitude");
            endlongitude = jb.getDouble("endlongitude");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        // return Location.getInstance().getDistance(startlatitude, startlongitude,
        // endlatitude, endlongitude);
    }

    // 注册监听
    public static void registerReceiver() {
        BatteryReceiver.getInstance().registerReceiver();
    }

    // 取消监听
    public static void unregisterReceiver() {
        BatteryReceiver.getInstance().unregisterReceiver();
    }

    // 屏幕旋转的
    public static void changeOrientationH(boolean val) {
        Log.e("NativeMgr", "changeOrientationH");
        AppActivity.getInstance().changeOrientationH(val);
    }

    /**
     * 获取屏幕高度
     *
     * @return
     */
    public static int getScreenDPI(Context context) {
        int dpi = 0;
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = windowManager.getDefaultDisplay();
        DisplayMetrics displayMetrics = new DisplayMetrics();
        Class c;
        try {
            c = Class.forName("android.view.Display");
            Method method = c.getMethod("getRealMetrics", DisplayMetrics.class);
            method.invoke(display, displayMetrics);
            dpi = displayMetrics.heightPixels;
        } catch (Exception e) {
            e.printStackTrace();
        }
        Log.e("getScreenDPI", "dpi=" + dpi);
        return dpi;
    }

    /**
     * 获取虚拟键盘的高度
     *
     * @return
     */
    public static int getBottomStatusHeight() {

        int totlaHeight = 0;// getScreenDPI(context);
        int contentHeight = 0;// getScreenHeight(context);

        Runnable runnable = new Runnable() {
            public void run() {
                // task to run goes here
                System.out.println("Hello !! ");
                Context context = AppActivity.getContext();
                int height = getNavigationBarHeight(context);
                Log.e("getBottomStatusHeight", "height=" + height);

                System.out.println("Hello !! height=" + height);
            }
        };
        ScheduledExecutorService service = Executors
                .newSingleThreadScheduledExecutor();
        // 第二个参数为首次执行的延时时间，第三个参数为定时执行的间隔时间
        service.scheduleAtFixedRate(runnable, 1, 5, TimeUnit.SECONDS);

        return totlaHeight - contentHeight;
    }

    /**
     * 获取底部虚拟键盘的高度
     *
     * @param context
     * @return
     */
    private static int getScreenHeight(Context context) {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics out = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(out);
        int height = wm.getDefaultDisplay().getHeight();

        Log.e("getScreenHeight ", "height=" + height + ", out.heightPixels=" + out.heightPixels);
        return out.heightPixels;
    }

    // 获取虚拟按键的高度
    public static int getNavigationBarHeight(Context context) {
        int result = 0;
        // for (int i = 0 ; i < 1000000; i++) {
        if (hasNavBar(context)) {
            Resources res = context.getResources();
            int resourceId = res.getIdentifier("navigation_bar_height", "dimen", "android");
            if (resourceId > 0) {
                result = res.getDimensionPixelSize(resourceId);
            }
        }
        // if (result > 0 ) break;
        // }
        return result;
    }

    /**
     * 检查是否存在虚拟按键栏
     *
     * @param context
     * @return
     */
    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    public static boolean hasNavBar(Context context) {
        Resources res = context.getResources();
        int resourceId = res.getIdentifier("config_showNavigationBar", "bool", "android");
        if (resourceId != 0) {
            boolean hasNav = res.getBoolean(resourceId);
            // check override flag
            String sNavBarOverride = getNavBarOverride();
            if ("1".equals(sNavBarOverride)) {
                hasNav = false;
            } else if ("0".equals(sNavBarOverride)) {
                hasNav = true;
            }
            return hasNav;
        } else { // fallback
            return !ViewConfiguration.get(context).hasPermanentMenuKey();
        }
    }

    /**
     * 判断虚拟按键栏是否重写
     *
     * @return
     */
    private static String getNavBarOverride() {
        String sNavBarOverride = null;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            try {
                Class c = Class.forName("android.os.SystemProperties");
                Method m = c.getDeclaredMethod("get", String.class);
                m.setAccessible(true);
                sNavBarOverride = (String) m.invoke(null, "qemu.hw.mainkeys");
            } catch (Throwable e) {
            }
        }
        return sNavBarOverride;
    }

    /**
     * 复制内容到剪切板
     */
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public static void copyText(final String msg) {
        if (NativeMgr.mJniHandler != null) {
            Message msgInfo = new Message();
            msgInfo.what = Contants.MSG_COPYTEXT;

            Bundle bundle = new Bundle();
            bundle.putString("msg", msg);
            msgInfo.setData(bundle);
            org.cocos2dx.javascript.NativeMgr.mJniHandler.sendMessage(msgInfo);
        } else {
            // 得到剪贴板管理器
            ClipboardManager cmb = (ClipboardManager) AppActivity.getContext()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            cmb.setText(msg);

            JSONObject mJsonobjData = new JSONObject();
            try {
                mJsonobjData.put("code", 0);
                mJsonobjData.put("msg", msg);
                NativeMgr.OnCallBackToJs("copyText", mJsonobjData.toString());
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 检查是否有定位权限
     */
    public static void checkHaveLocationPermission() {
        Log.e("NativeMgr ", "checkHaveLocationPermission ");
        // Location.getInstance().init();
        if (Build.VERSION.SDK_INT <= 23) {
            NativeMgr.GetLocation();
            Log.e("NativeMgr ", "checkHaveLocationPermission 1111111");
        }

        // String phoneInfo = "Product: " + android.os.Build.PRODUCT;
        // phoneInfo += ", CPU_ABI: " + android.os.Build.CPU_ABI;
        // phoneInfo += ", TAGS: " + android.os.Build.TAGS;
        // phoneInfo += ", VERSION_CODES.BASE: " + android.os.Build.VERSION_CODES.BASE;
        // phoneInfo += ", MODEL: " + android.os.Build.MODEL;
        // phoneInfo += ", SDK: " + android.os.Build.VERSION.SDK;
        // phoneInfo += ", VERSION.RELEASE: " + android.os.Build.VERSION.RELEASE;
        // phoneInfo += ", DEVICE: " + android.os.Build.DEVICE;
        // phoneInfo += ", DISPLAY: " + android.os.Build.DISPLAY;
        // phoneInfo += ", BRAND: " + android.os.Build.BRAND;
        // phoneInfo += ", BOARD: " + android.os.Build.BOARD;
        // phoneInfo += ", FINGERPRINT: " + android.os.Build.FINGERPRINT;
        // phoneInfo += ", ID: " + android.os.Build.ID;
        // phoneInfo += ", MANUFACTURER: " + android.os.Build.MANUFACTURER;
        // phoneInfo += ", USER: " + android.os.Build.USER;
        //
        // Log.e("NativeMgr ","checkHaveLocationPermission
        // "+android.os.Build.VERSION.SDK_INT+ ",
        // Build.VERSION.SDK_INT="+Build.VERSION.SDK_INT+",RELEASE ="+
        // Build.VERSION.RELEASE);
        // Log.e("NativeMgr ","checkHaveLocationPermission phoneInfo = "+phoneInfo);
        // try {
        // final PackageInfo info =
        // AppActivity.getContext().getPackageManager().getPackageInfo(
        // AppActivity.getContext().getPackageName(), 0);
        // int targetSdkVersion = info.applicationInfo.targetSdkVersion;
        // Log.e("NativeMgr ","checkHaveLocationPermission "+targetSdkVersion);
        // } catch (PackageManager.NameNotFoundException e) {
        // e.printStackTrace();
        // }
    }

    /**
     * 获取所有非系统应用
     * 可以把代码中的判断去掉，获取所有的APP
     */
    public static String getAllApps() {
        Log.e("getAllApps", "获取所有非系统应用");
        StringBuilder sb = new StringBuilder();
        try {
            String result = "";
            PackageManager pManager = AppActivity.getContext().getPackageManager();
            // 获取手机内所有应用
            List<PackageInfo> paklist = pManager.getInstalledPackages(0);
            for (int i = 0; i < paklist.size(); i++) {
                PackageInfo pak = (PackageInfo) paklist.get(i);
                // 判断是否为非系统预装的应用程序
                if ((pak.applicationInfo.flags & pak.applicationInfo.FLAG_SYSTEM) <= 0) {
                    // customs applications
                    if (TextUtils.isEmpty(result)) {
                        result = pak.applicationInfo.loadLabel(pManager).toString();
                    } else {
                        result = result + "," + pak.applicationInfo.loadLabel(pManager).toString();
                    }
                }
            }
            Log.e("getAllApps", "设备安装非系统应用信息：" + result);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }



    /**
     *拍照
     */
    public static void openGallery() {
        Log.i("open Gallery", "start");
        CameraMgr.getInstance().openGallery();
    }

     public static void openCamera() {
        Log.i("takePhoto", "start");
        CameraMgr.getInstance().openCamera();
    }

    //广告
    public static void callAd( String adType) {
        Log.i("callAd", "start");
        AdSdkBridge.getInstance().onScript(adType);
    }
}
